package com.neu.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.LinearLayout;

import com.neu.R;
import com.neu.adapter.RecAdapter;
import com.neu.bean.RecBean;

import java.util.ArrayList;
import java.util.List;


public class RecActivity extends AppCompatActivity {

    private RecyclerView rec;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rec);
        initView();
    }

    private void initView() {

        //数据源
        List<RecBean> list=new ArrayList<>();
        int[] imgs=new int[]{R.drawable.a1,R.drawable.a2,R.drawable.a3,R.drawable.a4,R.drawable.a5};
        //生成模拟数据
        for(int i=0;i<5;i++){
            RecBean r=new RecBean("我的图片"+i,imgs[i]);
            list.add(r);
        }

        //获得实例
        rec=findViewById(R.id.rec);
      //  LinearLayoutManager layoutManager=new LinearLayoutManager(this);
        GridLayoutManager layoutManager=new GridLayoutManager(this,3);
        //默认竖排
      //  layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rec.setLayoutManager(layoutManager);
        RecAdapter adapter=new RecAdapter(list);
        rec.setAdapter(adapter);

    }
}